package com.yn.pet.controller.app;


import com.yn.common.core.domain.AjaxResult;
import com.yn.pet.controller.pc.biz.PetBizService;
import com.yn.pet.controller.pc.request.CollectionQueryRequest;
import com.yn.pet.controller.pc.request.PetBindRequest;
import com.yn.pet.controller.pc.request.PetQueryRequest;
import com.yn.pet.controller.pc.request.PetRequest;
import com.yn.pet.controller.pc.response.PetResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;
import java.util.List;
import java.util.Set;

/**
 * 宠物(人)信息表(Pet)表控制层
 *
 * @author makejava
 * @since 2025-07-09 12:00:47
 */
@RestController
@AllArgsConstructor
@RequestMapping("/front/pet")
@Api(tags = "app端——宠物信息管理")
@Slf4j
public class APetController {

    private final PetBizService petBizService;

    /**
     * 用户绑定设备
     * @param imeis 支持多条imei，逗号分隔
     * @param groupId 分组ID
     * @return
     */
    @PostMapping("bindDevice")
    @ApiOperation("用户绑定设备")
    public AjaxResult bindDevice(@RequestParam(value = "imei", required = true) @NotNull String imeis,
                                 @RequestParam(value = "groupId", required = true)@NotNull Long groupId ) {
        log.info("用户绑定设备入参：imei:{}, groupId:{}",imeis,groupId);
        petBizService.bindDevice(imeis, groupId);
        return AjaxResult.success("绑定成功");
    }

    /**
     * 解绑设备信息
     * @param deviceId 设备ID
     * @return
     */
    @PostMapping("unBindDevice/{deviceId}")
    @ApiOperation("解绑设备信息")
    public AjaxResult unBindDevice(@PathVariable(required = true) @NotNull Long deviceId) {
        petBizService.unBindDevice(deviceId);
        return AjaxResult.success("解绑成功");
    }

    /**
     * 绑定设备到分组
     * @param deviceId 设备ID
     * @param groupId 分组ID
     * @return
     */
    @PostMapping("transferDevice")
    @ApiOperation("设备转移")
    public AjaxResult transferDevice(@RequestParam(required = true) @NotNull Long deviceId,
                                     @RequestParam(required = true) @NotNull Long groupId) {
        log.info("设备转移：deviceId:{},groupId:{}", deviceId,groupId);
        petBizService.transferDevice(deviceId, groupId);
        return AjaxResult.success("转移成功");
    }

    /**
     * 获取用户绑定设备列表
     * @return List<ImmediateLocationResponse>
     */
    @GetMapping("list")
    @ApiOperation("首页展示用户绑定设备列表")
    public AjaxResult list() {
        return AjaxResult.success(petBizService.deviceInfoList());
    }

    /**
     * 是否收藏设备（0 否 1是）
     * @param deviceId 设备id
     * @param isCollection 是否收藏 0 否 1是
     * @return 无
     */
    @PostMapping("collection")
    @ApiOperation("是否收藏设备")
    public AjaxResult collection(@RequestParam(required = true) @Validated Long deviceId, @RequestParam(required = true)Integer isCollection) {
        log.info("收藏设备入参：deviceId:{}, isCollection:{}",deviceId,isCollection);
        petBizService.collection(deviceId, isCollection);
        return AjaxResult.success();
    }

    /**
     * 分页查询用户关注列表
     * @param request 查询参数
     * @return IPage<CollectionQueryResponse>
     */
    @GetMapping("pageList")
    @ApiOperation("分页查询用户关注列表")
    public AjaxResult pageList(@RequestBody CollectionQueryRequest request) {
        log.info("分页查询用户关注列表入参：{}", request);
        return AjaxResult.success(petBizService.pageCollectionList(request));
    }


    @PostMapping("batch/cancelCollection")
    @ApiOperation("批量取消关注")
    public AjaxResult batchCancelCollection(@RequestParam @NotNull Set<Long> deviceIds) {
        log.info("批量取消关注入参：deviceIds{}", deviceIds);
        petBizService.batchCancelCollection(deviceIds);
        return AjaxResult.success("取消关注成功");
    }

}

